$(function(){
    show(549)
    $.ajax({
        url:"json/city.json",
        data:"",
        type:"get",
        dataType:"json",
        success:function(rs){
            var info;
            var info2;
            var str="";
            $(rs.result).each(function(){
                info = this.province;
                if(info != info2){
                    info2 = this.province;
                    str = str+"<option>"+this.province+"</option>";
                }
            });
            $("#select1").append(str);
        },
        error:function(){
            alert("省 查询 服务器资源异常！");
        }
    });
    $("#select1").change(function(){

        var province = $("#select1").val();
        $.ajax({
            url:"json/city.json",
            data:"",
            type:"get",
            dataType:"json",
            success:function(rs){
                var info;
                var info2;
                var str="<option>请选择所在地区</option>";
                $(rs.result).each(function(){
                    if(this.province==province){
                        info = this.city;
                        if(info != info2){
                            info2 = this.city;
                           // alert(info2)
                            str = str+"<option>"+this.city+"</option>";
                        }
                    }
                });
                $("#select2").html("");
               $("#select2").html(str);
            },
            error:function(){
                alert("市 查询 服务器资源异常！");
            }
        });
    });
    $("#select2").change(function(){
        var province = $("#select1").val();
        var city = $("#select2").val();
        $.ajax({
            url:"json/city.json",
            data:"",
            type:"get",
            dataType:"json",
            success:function(rs){
                var str="<option>请选择所在城市</option>";
                $(rs.result).each(function(){
                    if(this.province==province){
                        if(this.city==city){
                            //alert(this.district);
                            str = str+"<option>"+this.district+"</option>";
                        }
                    }
                });
                $("#select3").html("");
                $("#select3").html(str);
            },
            error:function(){
                alert("县/区 查询 服务器资源异常！");
            }
        });
    });

    $("#sel").click(function () {
        var province = $("#select1").val();
        var city = $("#select2").val();
        var district = $("#select3").val();
        $.ajax({
            url:"json/city.json",
            data:"",
            type:"get",
            dataType:"json",
            success:function(rs){
                var str="";
                var tem="";
                $(rs.result).each(function(){
                    if(this.province==province){
                        if(this.city==city){
                            if(this.district==district){
                                str = str+"<option>"+this.id+"</option>";
                                $("#cityid").val(this.id);
                                //alert(this.id)
                                show(this.id);
                            }
                        }
                    }
                });

            },
            error:function(){
                alert("县/区 查询 服务器资源异常！");
            }
        });
    });


});

var cityid;
var show = function(cityid){
    cityid  =$("#cityid").val();
    //alert(cityid);
    $.ajax({
        url:"http://v.juhe.cn/weather/index?format=1&cityname="+cityid+"&key=23c5dce5219268d65fb25a6c5c6e1c3e",
        data:"",
        type:"get",
        dataType:"jsonp",
        success:function(rs){
            
        },
        error:function(){
            alert("天气预报 查询 服务器资源异常！");
        }
    });
}